<?php


namespace App\Http\Controllers\Api;
use App\Http\Controllers\BaseController;
use App\Models\Category;
use App\Models\CookbookCollect;
use Illuminate\Http\Request;

class CookbookCollectController extends BaseController
{

    public $model = CookbookCollect::class;
    /**
     * 列表
     * @param Request $request
     * @return mixed
     */
    public function index(Request $request) {
        $title = $request->input('title');

        $users = CookbookCollect::title($title)->withCertain('cookbook', ['video_url', 'type'])->orderBy("id", "desc")
                ->paginate(\request('per_page', 20));
        return $this->paginate($users);
    }

    public function collectInfo(Request $request) {
        $this->validate($request, [
            'id' => 'required'
        ]);
        $id = \request('id');
        $info = CookbookCollect::withCertain('cookbook', ['video_url', 'type'])->find($id);
        if (!$info)
            return $this->failed('合集不存在');
        return $this->success($info);
    }

}

